using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using JGSY.CMS.LowCode.Platform.Application.DTOs;
using JGSY.CMS.LowCode.Platform.Application.Services;

namespace JGSY.CMS.LowCode.Platform.Application.Interfaces
{
    /// <summary>
    /// 审计日志应用服务接口。
    /// 提供系统操作审计日志的记录、查询、统计和管理等审计跟踪功能接口定义。
    /// </summary>
    public interface IAuditLogAppService
    {
        /// <summary>
        /// 获取所有审计日志
        /// </summary>
        /// <returns>审计日志列表</returns>
        Task<IEnumerable<AuditLogDto>> GetAllAsync();
        
        /// <summary>
        /// 根据ID获取审计日志
        /// </summary>
        /// <param name="id">审计日志标识符</param>
        /// <returns>审计日志信息</returns>
        Task<AuditLogDto?> GetByIdAsync(long id);
        
        /// <summary>
        /// 添加新的审计日志
        /// </summary>
        /// <param name="dto">审计日志数据传输对象</param>
        /// <returns>添加任务</returns>
        Task AddAsync(AuditLogDto dto);
        
        /// <summary>
        /// 查询审计日志
        /// </summary>
        /// <param name="type">操作类型</param>
        /// <param name="userId">用户标识符</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="resource">资源名称</param>
        /// <returns>符合条件的审计日志列表</returns>
        Task<IEnumerable<AuditLogDto>> QueryAsync(string type, long userId, DateTime? start, DateTime? end, string resource = "");

        /// <summary>
        /// 分页获取审计日志
        /// </summary>
        /// <param name="pageIndex">页索引，从1开始</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="type">操作类型过滤</param>
        /// <param name="userId">用户ID过滤</param>
        /// <param name="resource">资源过滤</param>
        /// <returns>分页结果</returns>
        Task<(List<AuditLogDto> Items, int TotalCount)> GetPagedAsync(
            int pageIndex = 1, 
            int pageSize = 20, 
            string? type = null, 
            string? userId = null, 
            string? resource = null);

        /// <summary>
        /// 获取审计日志统计信息
        /// </summary>
        /// <returns>统计信息</returns>
        Task<AuditLogStatisticsDto> GetStatisticsAsync();

        /// <summary>
        /// 批量添加审计日志
        /// </summary>
        /// <param name="dtos">审计日志列表</param>
        /// <returns>添加任务</returns>
        Task BatchAddAsync(IEnumerable<AuditLogDto> dtos);

        /// <summary>
        /// 清理过期的审计日志
        /// </summary>
        /// <param name="retentionDays">保留天数</param>
        /// <returns>被清理的记录数</returns>
        Task<int> CleanupAsync(int retentionDays = 90);

        /// <summary>
        /// 记录操作审计日志的便捷方法
        /// </summary>
        /// <param name="operationType">操作类型</param>
        /// <param name="content">操作内容</param>
        /// <param name="userId">用户ID</param>
        /// <param name="userName">用户名</param>
        /// <param name="ip">IP地址</param>
        /// <param name="resource">操作资源</param>
        /// <param name="result">操作结果</param>
        /// <param name="exception">异常信息</param>
        /// <returns>记录任务</returns>
        Task LogOperationAsync(
            string operationType,
            string content,
            string? userId = null,
            string? userName = null,
            string? ip = null,
            string? resource = null,
            string result = "Success",
            string? exception = null);
    }
}